<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/9
 * Time: 13:45
 */

namespace app\flower\controller;
use cmf\controller\AdminBaseController;
use app\flower\model\FlowerConfigModel;
class AdminIndexController extends AdminBaseController
{
    /**
     * 配置帮助中心和客户号码
     */
     public function config(){
          $config =  new FlowerConfigModel();
          $result =$config->get(1);
          $count = $config->count();
          $res = $result->getdata();
          if($count>0){
              $this->assign('id',$res['id']);
              $this->assign('phone',$res['aftersale']);
              $this->assign('helpcenter',$res['helpsenter']);
              $this->assign('knows',htmlspecialchars_decode($res['knows']));
              $this->assign('service',htmlspecialchars_decode($res['service']));
          }else{
              $this->assign('id','');
              $this->assign('phone','');
              $this->assign('helpcenter','');
              $this->assign('knows','');
              $this->assign('service','');
          }
          return $this->fetch('config');
     }

    /**
     *配置信息修改
     *
     */
    public function configEdit(){
          $config =  new FlowerConfigModel();
          $id = input('id');
          $phone = input('phone');
          $helpcenter = input('helpcenter');
          $knows = input('knows.post_content');
          $service = input('service.post_content');
          if(empty($id)){
              $config->aftersale =$phone;
              $config->helpsenter =$helpcenter;
              $config->knows = $knows;
              $config->service = $service;
              $result = $config->save();
              if($result!=false){
                 $this->success('添加成功','config');
              }else{
                  $this->error('添加失败');
              }
          }else{
              $result = $config->where(array('id'=>$id))->update(array('aftersale'=>$phone,'helpsenter'=>$helpcenter,'knows'=>$knows,'service'=>$service,'dottime'=>time()));
              if($result>0){
                  $this->success('添加成功','config');
              }else{
                  $this->error('添加失败');
              }
          }
    }


}